package com.aididi;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import sun.rmi.runtime.Log;

@SpringBootApplication
@Slf4j
public class SpringbootResttemplateApplication {


	@Bean
	public RestTemplate restTemplate(RestTemplateBuilder builder){
		 return builder.build();
	}

	/**
	 *
	 * @param restTemplate
	 * @return	启动时执行
	 */
	@Bean
	public CommandLineRunner run(RestTemplate restTemplate){
		return args -> {
			String result = restTemplate.getForObject("http://gturnquist-quoters.cfapps.io/api/random",String.class);
			log.info(result.toString());
		};

	}

	public static void main(String[] args) {
		SpringApplication.run(SpringbootResttemplateApplication.class, args);
	}

}
